package com.jpsl.core.reflection.property.f;

import com.jpsl.core.reflection.property.MetaClassSupport;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * 通过 {@link Field} 来直接取值和赋值
 *
 * @author 懒王猫
 */
public class ByFieldMetaClass extends MetaClassSupport {

    public ByFieldMetaClass(Class<?> beanType) {
        super(beanType);
    }

    @Override
    protected void init() {
        for (Class<?> clazz = beanType; clazz != Object.class; clazz = clazz.getSuperclass()) {
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                if (!Modifier.isStatic(field.getModifiers())) {
                    addProperty(field.getName());
                    addGetter(new ByFieldPropertyValueGetter(field.getName(), field));
                    addSetter(new ByFieldPropertyValueSetter(field.getName(), field));
                }
            }
        }
    }

}
